<?	/*
	// File:	webalizer.php
	// Purpose:	Generates webalizer runs for every domains and sub-domains (NOT domain pointer)
	// Creation:	2002-02-22
	// Author:	Felix <webmaster@can-host.com>
	*/

$dbp = mysql_query("SELECT host,domain,path,id FROM domains WHERE type='domain' OR type='subdomain'");
if ($dbp) {
	while ($data = mysql_fetch_array($dbp)) {
		$domaindata = fetchdata("serverside","domain",$data['id']);
		if ($domaindata['serverside']['webalizer'] == 'on') {
			
			$access = $data['path']."/".$data['host']."/logs/access";
		//	$stats = $data['path']."/".$data['host']."/".$cfg['webname']."/stats";
				$stats = $data['path']."/".$data['host']."/stats";
			$dom = $data['domain'];
			$host = $data['host'];
			
			if (file_exists($access)) {
				// Create target
				if (!@is_dir($stats)) {
					mkdir($stats, 0755);
				}
					chmod($stats, 0755);
					chown($stats,'root');
					chgrp($stats,'root');
		/*
				if (($data['owner']>1000000000) || ($data['type'] == "subdomain")) {
					chgrp($stats,"g".$data['owner']);
				} else {
					chgrp($stats,"g".$data['id']);
				}
		*/				
				// run webalizer
				exec($cfg['prog']['webalizer']." -Q -p -n $host.$dom -o $stats -R 50 -S 50 -U 50 $access 2>&1",$cronresults,$result);
				
				// If any error happen (hence a return)
				if ($cronresults) {
					if (is_array($cronresults)) $cronresults = implode("",$cronresults);
					webcp_log(1,0,"webalizer","webalizer ERROR: $host.$dom [".$data['id']."] ($cronresults)",0);
				}
			}
		}
	}
} else {
	webcp_log(2,0,"webalizer","webalizer ERROR: no domains",0);
}
?>
